package com.vercon.moensmart.adapter

import android.content.Context
import android.net.Uri
import android.view.LayoutInflater
import android.view.ViewGroup
import com.vercon.moensmart.adapter.base.BaseAdapter
import com.vercon.moensmart.databinding.ItemAdCardLayoutBinding
import com.vercon.moensmart.mode.response.Inspiration
import com.vercon.moensmart.utils.FrescoUtil

class AdCardAdapter(context: Context?) : BaseAdapter<ItemAdCardLayoutBinding, Inspiration.ListDTO?>(context) {
    private var index = 0
    fun setCurrentIndex(index: Int) {
        this.index = index
        notifyDataSetChanged()
    }

    override fun baseViewHolder(parent: ViewGroup): ViewHolder {
        val binding: ItemAdCardLayoutBinding = ItemAdCardLayoutBinding.inflate(LayoutInflater.from(context), parent, false)
        return ViewHolder(binding)
    }

    override fun bindItemView(viewHolder: BaseViewHolder?, position: Int, t: Inspiration.ListDTO?, total: Int) {
        viewHolder?.mBinding?.tvTitle?.text = t?.title
        FrescoUtil.loadRoundedImage(viewHolder?.mBinding?.pictureImageview,16, Uri.parse(t?.image),context)
        viewHolder?.itemView?.setOnClickListener {
            mItemListener?.onItemClickListener(it,t,position)
        }
    }
    inner class ViewHolder(itemBinding: ItemAdCardLayoutBinding) : BaseViewHolder(itemBinding)
}